package payrechargelogic

import (
	"context"

	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/recharge"
	schema "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/recharge"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeVipLevelListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRechargeVipLevelListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeVipLevelListLogic {
	return &RechargeVipLevelListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RechargeVipLevelListLogic) RechargeVipLevelList(in *rpc.RechargeVipLevelListRequest) (*rpc.RechargeVipLevelListResponse, error) {
	var (
		CommonResp rpc.CommonResp
		vipList    []schema.RechargeVip
		err        error
	)

	vipList, err = model.NewRechargeVipModel(l.ctx, l.svcCtx.Db).GetAllRechargeVip(in)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Database operation error"
		return &rpc.RechargeVipLevelListResponse{
			CommonResp: &CommonResp,
		}, err
	}

	var records []*rpc.VipLevel

	for _, record := range vipList {
		records = append(records, &rpc.VipLevel{
			Id:     record.ID,
			Level:  record.Level,
			Times:  record.RechargeTimes,
			Amount: record.RechargeAmount,
		})
	}

	CommonResp.Message = "Success"
	return &rpc.RechargeVipLevelListResponse{
		Records:    records,
		CommonResp: &CommonResp,
	}, nil
}
